import pymysql

class Db:
    def __init__(self):
        self.conn = pymysql.connect(host='localhost',port=3306,user='root',
                                    password='root',db='p9first',charset='utf8',
                                    cursorclass=pymysql.cursors.DictCursor)
        self.cour = self.conn.cursor()


    def update(self,sql):
        self.cour.execute(sql)
        self.conn.commit()

    def find(self,sql):
        self.conn.ping(reconnect=True)
        self.cour.execute(sql)
        return self.cour.fetchone()

    def findall(self,sql):
        self.conn.ping(reconnect=True)
        self.cour.execute(sql)
        return self.cour.fetchall()

    def close(self):
        self.cour.close()
        self.conn.close()



db1 = Db()

